<?php
class Form_Element_Images extends Form_Base
{
    private static $_current = NULL;
    private $_has_include_upload_js;

    public static function current()
    {
        if (NULL === self::$_current)
        {
            self::$_current = new Form_Element_Images;
        }

        return self::$_current;
    }

    public function __construct ()
    {
        $this->_has_include_upload_js = 0;
    }

    public function build_show($rs)
    {
        $content = View::factory('smarty:form/images')
            ->set('upload_input_name', $rs['input_name'])
            ->set('image_list', $rs['value'])
            ->set('action_type', 'detail')
            ->render();

        $this->_has_include_upload_js = 0;
        return $content;
    }



    public function build_form($rs)
    {
        $timestamp = time();
        $upload = array(
            'timestamp' => $timestamp,
            'token'     => md5('unique_salt' . $timestamp),
        );

        $content = View::factory('smarty:form/images')
            ->set('upload', $upload)
            ->set('has_include_upload_js', $this->_has_include_upload_js)
            ->set('upload_input_name', $rs['input_name'])
            ->set('image_list', $rs['value'])
            ->set('input_type', $rs['input_type'])
            ->set('action_type', 'form')
            ->render();

        $this->_has_include_upload_js = 1;
        return $content;
    }

    private function explode_images ($imglist_str)
    {
        print_r($imglist_str);exit;
        $imgs = explode('|', $imglist_str);
        $images = array();
        foreach ($imgs as $img)
        {
            $img = trim($img);
            if (! $img)
                continue;
            $images[] = $img;
        }

        return $images;
    }
}
